package com.pureut.storage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.storage.domain.PickingSchemeRelation;
import com.pureut.storage.mapper.PickingSchemeRelationMapper;
import com.pureut.storage.service.PickingSchemeRelationService;
import com.pureut.system.api.domain.SysDictData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/***
 *
 * Author:C
 * Date:2022/12/21 15:45
 * @DESC
 */
@Service
public class PickingSchemeRelationServiceImpl extends ServiceImpl<PickingSchemeRelationMapper, PickingSchemeRelation> implements PickingSchemeRelationService {

    @Resource
    PickingSchemeRelationMapper pickingSchemeRelationMapper;

    @Override
    public List<PickingSchemeRelation> getRelationList(Long id) {
        //获取仓库单据字典
        List<SysDictData> pickingStrategyArray = DictUtils.getDictCache("picking_strategy_choice");
        Map<String, String> pickingStrategyMap = pickingStrategyArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        //管控类型字典
        List<SysDictData> controlTypeArray = DictUtils.getDictCache("control_type");
        Map<String, String> controlTypeMap = controlTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        List<PickingSchemeRelation> pickingSchemeRelations = pickingSchemeRelationMapper.selectList(new QueryWrapper<PickingSchemeRelation>().lambda().eq(PickingSchemeRelation::getPickingId, id));
        for (PickingSchemeRelation entity : pickingSchemeRelations) {
            if ("1".equals(entity.getControlType())) {
               entity.setAssociatedDetails(pickingStrategyMap.get(entity.getAssociatedDetails()));
            }
            //管控类型
            entity.setControlType(controlTypeMap.get(entity.getControlType()));
        }
        return pickingSchemeRelations;
    }
}
